package model.dao.registerOrder;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import log.MyLogger;
import model.service.ServiceRequestStatusType;

public class ServiceRequestStatusTypeDAOImpl {

	String sql = "" ;
	db.dbconnection dbconnection ;
	Connection myConnection ;
	Statement st ;
	
	public ServiceRequestStatusType getServiceRequestStatusTypeById(int serviceRequestStatusTypeId) {
		ServiceRequestStatusType serviceRequestStatusType = new ServiceRequestStatusType();
		serviceRequestStatusType.setServiceRequestStatusType(serviceRequestStatusTypeId);
		try {
			myConnection = dbconnection.getConnection();
			Statement st = myConnection.createStatement();
			String sql = "SELECT * FROM service_request_status_type WHERE service_request_status_type = "+ serviceRequestStatusTypeId;
			ResultSet r = st.executeQuery(sql);
			while(r.next()){
				serviceRequestStatusType.setTypeName(r.getString("type_name"));
			}
			this.dbconnection.close();
		} catch (Exception e) {
//			MyLogger.Log("ServiceRequestStatusTypeDAOImpl.getServiceRequestStatusTypeById()", e.getMessage());
		}
		return serviceRequestStatusType;
	}

	public List<ServiceRequestStatusType> getStatusTypes() {
		List<ServiceRequestStatusType> t = new ArrayList<ServiceRequestStatusType>();
		try {
			myConnection = dbconnection.getConnection();
			Statement st = myConnection.createStatement();
			String sql = "SELECT service_request_status_type FROM service_request_status_type";
			ResultSet r = st.executeQuery(sql);
			
			while(r.next()){
				t.add(getServiceRequestStatusTypeById(r.getInt("service_request_status_type")));
			}
			this.dbconnection.close();
		} catch (Exception e) {
//			MyLogger.Log("ServiceRequestStatusTypeDAOImpl.getStatusTypes()", e.getMessage());
		}
		return t;
	}

}
